﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Presentation.Web.Client.Models;

namespace Presentation.Web.Client.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            var salesActionLinksCollectionBlock = GetSalesActionLinksCollectionBlock();
            var procurementActionLinksCollectionBlock = GetProcurementActionLinksCollectionBlock();
            var warehousingActionLinksCollectionBlock = GetWarehousingActionLinksCollectionBlock();
            var humanResourcesActionLinksCollectionBlock = GetHumanResourcesActionLinksCollectionBlock();

            var miniBlocksCollection = new List<LinksCollectionViewModel>
                                           {
                                               salesActionLinksCollectionBlock,
                                               procurementActionLinksCollectionBlock,
                                               warehousingActionLinksCollectionBlock,
                                               humanResourcesActionLinksCollectionBlock
                                           };

            ViewBag.MiniBlocksCollection = miniBlocksCollection;
            return View();
        }

        #region Private Methods

        private LinksCollectionViewModel GetSalesActionLinksCollectionBlock()
        {
            var salesActionLinksCollectionBlock = new LinksCollectionViewModel("Sales");

            var salesLinksCollection = new List<Link>
                                           {
                                               new Link
                                                   {
                                                       Name = "Order",
                                                       Action = "Create",
                                                       Control = "Orders",
                                                       Area = "SalesManagement"
                                                   },
                                               new Link
                                                   {
                                                       Name = "Invoice",
                                                       Action = "Create",
                                                       Control = "Invoices",
                                                       Area = "SalesManagement"
                                                   },
                                               new Link
                                                   {
                                                       Name = "Return",
                                                       Action = "Create",
                                                       Control = "Orders",
                                                       Area = "SalesManagement"
                                                   },
                                               new Link
                                                   {
                                                       Name = "Customer",
                                                       Action = "Create",
                                                       Control = "Customers",
                                                       Area = "SalesManagement"
                                                   }

                                           };
            salesLinksCollection.ForEach(link => salesActionLinksCollectionBlock.Links.Add(link));
            return salesActionLinksCollectionBlock;
        }

        private LinksCollectionViewModel GetProcurementActionLinksCollectionBlock()
        {
            var procurementActionLinksCollectionBlock = new LinksCollectionViewModel("Procurement");

            var procurementLinksCollection = new List<Link>
                                           {
                                               new Link
                                                   {
                                                       Name = "Purchase order",
                                                       Action = "Create",
                                                       Control = "SalesOrders",
                                                       Area = "ProcurementManagement"
                                                   },
                                               new Link
                                                   {
                                                       Name = "Supplier",
                                                       Action = "Create",
                                                       Control = "Suppliers",
                                                       Area = "ProcurementManagement"
                                                   },
                                           };
            procurementLinksCollection.ForEach(link => procurementActionLinksCollectionBlock.Links.Add(link));
            return procurementActionLinksCollectionBlock;
        }

        private LinksCollectionViewModel GetWarehousingActionLinksCollectionBlock()
        {
            var warehousesActionLinksCollectionBlock = new LinksCollectionViewModel("Warehouse");

            var warehousesLinksCollection = new List<Link>
                                           {
                                               new Link
                                                   {
                                                       Name = "Product",
                                                       Action = "Create",
                                                       Control = "Nomenclatures",
                                                       Area = "WarehouseManagement"
                                                   },
                                               new Link
                                                   {
                                                       Name = "Stock moves",
                                                       Action = "Create",
                                                       Control = "Stocks",
                                                       Area = "WarehouseManagement"
                                                   },
                                                   new Link
                                                   {
                                                       Name = "Warehouse",
                                                       Action = "Create",
                                                       Control = "Warehouses",
                                                       Area = "WarehouseManagement"
                                                   },
                                           };
            warehousesLinksCollection.ForEach(link => warehousesActionLinksCollectionBlock.Links.Add(link));
            return warehousesActionLinksCollectionBlock;
        }

        private LinksCollectionViewModel GetHumanResourcesActionLinksCollectionBlock()
        {
            var humanResourcesActionLinksCollectionBlock = new LinksCollectionViewModel("Human resources");

            var salesLinksCollection = new List<Link>
                                           {
                                               new Link
                                                   {
                                                       Name = "Employee",
                                                       Action = "Create",
                                                       Control = "Employee",
                                                       Area = "HumanResourcesManagement"
                                                   },
                                               new Link
                                                   {
                                                       Name = "Redeployment",
                                                       Action = "Create",
                                                       Control = "Redeployment",
                                                       Area = "HumanResourcesManagement"
                                                   },
                                                  
                                           };
            salesLinksCollection.ForEach(link => humanResourcesActionLinksCollectionBlock.Links.Add(link));
            return humanResourcesActionLinksCollectionBlock;
        }
        #endregion
    }


}
